<?php

namespace App\Http\Controllers\CRM\MiniAPP;

use App\Helper\ApiResponseHelper;
use App\Http\Controllers\Controller;
use App\Http\Requests\CRM\MiniAPP\AssistantRequest;
use App\Http\Resources\CRM\MiniAPP\AssistantResource;
use App\Models\FakeAssistant;
use Illuminate\Http\Request;

class AssistantController extends Controller
{
    public function getList()
    {
        $assistants = FakeAssistant::with('type')->latest()->get();

        return AssistantResource::collection($assistants);
    }

    public function getInfo(FakeAssistant $assistant)
    {
        return new AssistantResource($assistant);
    }

    public function create(AssistantRequest $request)
    {
        $assistant = FakeAssistant::create($request->only([
            'avatar', 'name', 'hour_price', 'fake_assistant_type_id', 'pictures',
        ]));

        return new AssistantResource($assistant);
    }

    public function edit(FakeAssistant $assistant, AssistantRequest $request)
    {
        $assistant->update($request->only([
            'avatar', 'name', 'hour_price', 'fake_assistant_type_id', 'pictures',
        ]));

        return new AssistantResource($assistant);
    }

    public function remove(FakeAssistant $assistant)
    {
        $assistant->delete();

        return ApiResponseHelper::json([]);
    }

    //修改详细信息
    public function editDetail(FakeAssistant $assistant, Request $request)
    {
        $assistant->update($request->only([
            'real_name', 'birthday', 'age', 'phone', 'character', 'constellation', 'address', 'interest', 'hobby',
            'relationship', 'height', 'weight', 'bust', 'waist', 'hip', 'skin', 'communication', 'emotion', 'love',
            'family', 'job', 'income', 'menstruation', 'body', 'experience',
        ]));

        return new AssistantResource($assistant);
    }
}
